<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Arduino FDK AAC Encoder and Decoder Library: src/AACDecoderFDK.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Arduino FDK AAC Encoder and Decoder Library
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">AACDecoderFDK.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160; </div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &lt;stdint.h&gt;</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#include &quot;fdk_log.h&quot;</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#include &quot;libAACdec/aacdecoder_lib.h&quot;</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160; </div>
<div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="namespaceaac__fdk.html">    9</a></span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceaac__fdk.html">aac_fdk</a> {</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="keyword">typedef</span> void (*AACInfoCallbackFDK)(CStreamInfo &amp;info);</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="keyword">typedef</span> void (*AACDataCallbackFDK)(CStreamInfo &amp;info,INT_PCM *pcm_data, <span class="keywordtype">size_t</span> len);</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160; </div>
<div class="line"><a name="l00018"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html">   18</a></span>&#160;<span class="keyword">class </span><a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html">AACDecoderFDK</a>  {</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;    <span class="keyword">public</span>:</div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a93d96e7403aa314c67c26bce6f6071bd">   25</a></span>&#160;        <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a93d96e7403aa314c67c26bce6f6071bd">AACDecoderFDK</a>(<span class="keywordtype">int</span> output_buffer_size=2048){</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;            LOG(Debug,__FUNCTION__);</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;            this-&gt;output_buffer_size = output_buffer_size;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;            this-&gt;output_buffer = <span class="keyword">new</span> INT_PCM[output_buffer_size];</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        }</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160; </div>
<div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a50eb9ec47b72f7e251f53ae9d787b6c7">   38</a></span>&#160;        <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a50eb9ec47b72f7e251f53ae9d787b6c7">AACDecoderFDK</a>(AACDataCallbackFDK dataCallback, AACInfoCallbackFDK infoCallback=<span class="keyword">nullptr</span>, <span class="keywordtype">int</span> output_buffer_size=2048){</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;            this-&gt;output_buffer_size = output_buffer_size;</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;            this-&gt;output_buffer = <span class="keyword">new</span> INT_PCM[output_buffer_size];</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;            setDataCallback(dataCallback);</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;            setInfoCallback(infoCallback);</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        }</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160; </div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="preprocessor">#ifdef ARDUINO</span></div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a93d96e7403aa314c67c26bce6f6071bd">AACDecoderFDK</a>(Stream &amp;out_stream, <span class="keywordtype">int</span> output_buffer_size=2048){</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;            LOG(Debug,__FUNCTION__);</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;            this-&gt;output_buffer_size = output_buffer_size;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;            this-&gt;output_buffer = <span class="keyword">new</span> INT_PCM[output_buffer_size];</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;            <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a024569eb041a55ca2771d03cc743c312">setStream</a>(out_stream)</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        }</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160; </div>
<div class="line"><a name="l00055"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a024569eb041a55ca2771d03cc743c312">   55</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a024569eb041a55ca2771d03cc743c312">setStream</a>(Stream &amp;out_stream){</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;            this-&gt;out = &amp;out_stream;</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        }</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160; </div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        ~<a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html">AACDecoderFDK</a>(){</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;            end();</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;        }</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160; </div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        <span class="keywordtype">void</span> setInfoCallback(AACInfoCallbackFDK cb){</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;            this-&gt;infoCallback = cb;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        }</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160; </div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        <span class="keywordtype">void</span> setDataCallback(AACDataCallbackFDK cb){</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;            this-&gt;pwmCallback = cb;</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;        }</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160; </div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ad06ab9a7174c1bd49dda1f0632012c2a">   85</a></span>&#160;        <span class="keywordtype">int</span> <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ad06ab9a7174c1bd49dda1f0632012c2a">setRawConfig</a>(<span class="keywordtype">void</span>* cfg, UINT &amp;len){</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;            uint8_t *ptr = (uint8_t *)cfg;</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;            <span class="keywordflow">return</span> aacDecoder_ConfigRaw(aacDecoderInfo, &amp;ptr, &amp;len);</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        }</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ac0a9f3a247c5d46eceeb7d72ff355386">  101</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ac0a9f3a247c5d46eceeb7d72ff355386">setDecoderFlags</a>(<span class="keywordtype">int</span> flags){</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;            decoder_flags = flags;</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        }</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160; </div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        <span class="comment">// opens the decoder</span></div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        <span class="keywordtype">void</span> begin(<a class="code" href="namespaceaac__fdk.html#a2778be91ce5b9583922e12ed14800ab7">TRANSPORT_TYPE</a> transportType=<a class="code" href="namespaceaac__fdk.html#a2778be91ce5b9583922e12ed14800ab7a4dcca5bcc4b82568da4a32aaf231966b">TT_MP4_ADTS</a>, UINT nrOfLayers=1){</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;            LOG(Debug,__FUNCTION__);</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;            <span class="keywordtype">int</span> error;</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;            aacDecoderInfo = aacDecoder_Open(transportType, nrOfLayers);</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;            <span class="keywordflow">if</span> (aacDecoderInfo==NULL){</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;                LOG(Error,<span class="stringliteral">&quot;aacDecoder_Open -&gt; Error&quot;</span>);</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;                <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;            }</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160; </div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;            <span class="comment">// if we decode 1 channel aac files we return output to 2 channels</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;            aacDecoder_SetParam(aacDecoderInfo, <a class="code" href="namespaceaac__fdk.html#a418a271f19e3b10156f92bc22288bbaea2f63d9b1bf4936c0572557d1da16bff5">AAC_PCM_MIN_OUTPUT_CHANNELS</a>, 2);</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;            is_open = <span class="keyword">true</span>;</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;            <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        }</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160; </div>
<div class="line"><a name="l00128"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a6e9a700cc1e8433b54a31c64800a7627">  128</a></span>&#160;        AAC_DECODER_ERROR <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a6e9a700cc1e8433b54a31c64800a7627">configure</a>(uint8_t *conf, <span class="keyword">const</span> uint32_t &amp;length) {</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;            <span class="keywordflow">return</span> aacDecoder_ConfigRaw (aacDecoderInfo, &amp;conf, &amp;length );</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;        }</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160; </div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;        <span class="comment">// write AAC data to be converted to PCM data - we feed the decoder witch batches of max 1k</span></div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> write(<span class="keyword">const</span> <span class="keywordtype">void</span> *in_ptr, <span class="keywordtype">size_t</span> in_size) {</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;            LOG(Debug,<span class="stringliteral">&quot;write %zu bytes&quot;</span>, in_size);</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;            uint8_t *byte_ptr = (uint8_t *)in_ptr;</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;            <span class="keywordtype">size_t</span> open = in_size;</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;            <span class="keywordtype">int</span> pos = 0;</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;            <span class="keywordflow">while</span>(open&gt;0){</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;                <span class="comment">// a frame is between 1 and 768 bytes =&gt; so we feed the decoder with small chunks</span></div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;                <span class="keywordtype">size_t</span> len = min(open, 256);</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;                <span class="keywordtype">int</span> decoded = <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#acc5e09c10e95d152a3deb09377e85a22">decode</a>(byte_ptr+pos, len);</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;                pos+=decoded;</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;                open-=decoded;</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;            }</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;            <span class="keywordflow">return</span> pos;</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;        }</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160; </div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;        <span class="comment">// provides detailed information about the stream</span></div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;        CStreamInfo &amp;audioInfo(){</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;            <span class="keywordflow">return</span> *aacDecoder_GetStreamInfo(aacDecoderInfo);</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;        }</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160; </div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;        <span class="comment">// release the resources</span></div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;        <span class="keywordtype">void</span> end(){</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;            LOG(Debug,__FUNCTION__);</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;            <span class="keywordflow">if</span> (aacDecoderInfo!=<span class="keyword">nullptr</span>){</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;                aacDecoder_Close(aacDecoderInfo); </div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;                aacDecoderInfo = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;            }</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;            <span class="keywordflow">if</span> (output_buffer!=<span class="keyword">nullptr</span>){</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;                <span class="keyword">delete</span>[] output_buffer;</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;                output_buffer = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;            }</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;            is_open = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;        }</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160; </div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;       <span class="keyword">virtual</span> <span class="keyword">operator</span> boolean() {</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;           <span class="keywordflow">return</span> is_open;</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;       }</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160; </div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;        <span class="keywordtype">bool</span> is_cleanup_stream = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;        HANDLE_AACDECODER aacDecoderInfo;</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;        <span class="keywordtype">int</span> output_buffer_size = 0;</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;        INT_PCM* output_buffer = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;        <span class="keywordtype">bool</span> is_open = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;        CStreamInfo aacFrameInfo;</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;        AACDataCallbackFDK pwmCallback = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;        AACInfoCallbackFDK infoCallback = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;        <span class="keywordtype">int</span> decoder_flags = 0;</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160; </div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="preprocessor">#ifdef ARDUINO</span></div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;        Stream *out = <span class="keyword">nullptr</span>;</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160; </div>
<div class="line"><a name="l00187"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#acc5e09c10e95d152a3deb09377e85a22">  187</a></span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#acc5e09c10e95d152a3deb09377e85a22">decode</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *in_ptr, <span class="keywordtype">size_t</span> in_size) {</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;            LOG(Debug,<span class="stringliteral">&quot;write %zu bytes&quot;</span>, in_size);</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;            <span class="keywordtype">size_t</span> result = 0;</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;            </div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;            AAC_DECODER_ERROR error; </div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;            <span class="keywordflow">if</span> (aacDecoderInfo!=<span class="keyword">nullptr</span>) {</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;                uint32_t bytesValid = in_size;</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;                <span class="keyword">const</span> <span class="keywordtype">void</span> *start = in_ptr;</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;                error = aacDecoder_Fill(aacDecoderInfo, (UCHAR **)&amp;start, (<span class="keyword">const</span> UINT*)&amp;in_size, &amp;bytesValid); </div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;                <span class="keywordflow">while</span> (error == AAC_DEC_OK) {</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;                    error = aacDecoder_DecodeFrame(aacDecoderInfo, output_buffer, output_buffer_size, decoder_flags); </div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;                    <span class="comment">// write pcm to output stream</span></div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;                    <span class="keywordflow">if</span> (error == AAC_DEC_OK){</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                        <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ae672eb855a6c8c428f3da83c8edd0a9c">provideResult</a>(output_buffer, output_buffer_size);</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                    } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;                        LOG(Error,<span class="stringliteral">&quot;Decoding error: %d&quot;</span>,error);</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;                    }</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;                    <span class="comment">// if not all bytes were used we process them now</span></div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;                    <span class="keywordflow">if</span> (bytesValid&gt;0){</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;                        <span class="keyword">const</span> uint8_t *start = <span class="keyword">static_cast&lt;</span><span class="keyword">const </span>uint8_t*<span class="keyword">&gt;</span>(in_ptr)+bytesValid;</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;                        uint32_t act_len = in_size-bytesValid;</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;                        error = aacDecoder_Fill(aacDecoderInfo, (UCHAR**) &amp;start, &amp;act_len, &amp;bytesValid);</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;                    }</div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;                }</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;            }</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;            <span class="keywordflow">return</span> in_size;</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;        }</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160; </div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160; </div>
<div class="line"><a name="l00217"></a><span class="lineno"><a class="line" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ae672eb855a6c8c428f3da83c8edd0a9c">  217</a></span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ae672eb855a6c8c428f3da83c8edd0a9c">provideResult</a>(INT_PCM *data, <span class="keywordtype">size_t</span> len){</div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;            LOG(Debug, <span class="stringliteral">&quot;provideResult: %zu samples&quot;</span>,len);</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;             <span class="keywordflow">if</span> (len&gt;0){</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;                 CStreamInfo info = audioInfo();</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;                <span class="comment">// provide result</span></div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;                <span class="keywordflow">if</span>(pwmCallback!=<span class="keyword">nullptr</span>){</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;                    <span class="comment">// output via callback</span></div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;                    pwmCallback(info, data,len);</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;                } <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;                    <span class="comment">// output to stream</span></div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;                    <span class="keywordflow">if</span> (info.aacSampleRate!=aacFrameInfo.aacSampleRate &amp;&amp; infoCallback!=<span class="keyword">nullptr</span>){</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;                        infoCallback(info);</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;                    }</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;<span class="preprocessor">#ifdef ARDUINO</span></div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;                    out-&gt;write((uint8_t*)pwm_buffer, data, len*<span class="keyword">sizeof</span>(INT_PCM));</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;                }</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;                aacFrameInfo = info;</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;            }</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;        }            </div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160; </div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;};</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160; </div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;}</div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html">aac_fdk::AACDecoderFDK</a></div><div class="ttdoc">Audio Decoder which decodes AAC into a PCM stream.</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:18</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_a024569eb041a55ca2771d03cc743c312"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a024569eb041a55ca2771d03cc743c312">aac_fdk::AACDecoderFDK::setStream</a></div><div class="ttdeci">void setStream(Stream &amp;out_stream)</div><div class="ttdoc">Defines the output stream.</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:55</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_a50eb9ec47b72f7e251f53ae9d787b6c7"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a50eb9ec47b72f7e251f53ae9d787b6c7">aac_fdk::AACDecoderFDK::AACDecoderFDK</a></div><div class="ttdeci">AACDecoderFDK(AACDataCallbackFDK dataCallback, AACInfoCallbackFDK infoCallback=nullptr, int output_buffer_size=2048)</div><div class="ttdoc">Construct a new AACDecoderFDK object.</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:38</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_a6e9a700cc1e8433b54a31c64800a7627"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a6e9a700cc1e8433b54a31c64800a7627">aac_fdk::AACDecoderFDK::configure</a></div><div class="ttdeci">AAC_DECODER_ERROR configure(uint8_t *conf, const uint32_t &amp;length)</div><div class="ttdoc">Explicitly configure the decoder by passing a raw AudioSpecificConfig (ASC) or a StreamMuxConfig (SMC...</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:128</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_a93d96e7403aa314c67c26bce6f6071bd"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#a93d96e7403aa314c67c26bce6f6071bd">aac_fdk::AACDecoderFDK::AACDecoderFDK</a></div><div class="ttdeci">AACDecoderFDK(int output_buffer_size=2048)</div><div class="ttdoc">Construct a new AACDecoderFDK object.</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:25</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_ac0a9f3a247c5d46eceeb7d72ff355386"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ac0a9f3a247c5d46eceeb7d72ff355386">aac_fdk::AACDecoderFDK::setDecoderFlags</a></div><div class="ttdeci">void setDecoderFlags(int flags)</div><div class="ttdoc">Set the Decoder Flags object Bit field with flags for the decoder:   (flags &amp; AACDEC_CONCEAL) == 1: D...</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:101</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_acc5e09c10e95d152a3deb09377e85a22"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#acc5e09c10e95d152a3deb09377e85a22">aac_fdk::AACDecoderFDK::decode</a></div><div class="ttdeci">virtual size_t decode(const void *in_ptr, size_t in_size)</div><div class="ttdoc">decodes the data</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:187</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_ad06ab9a7174c1bd49dda1f0632012c2a"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ad06ab9a7174c1bd49dda1f0632012c2a">aac_fdk::AACDecoderFDK::setRawConfig</a></div><div class="ttdeci">int setRawConfig(void *cfg, UINT &amp;len)</div><div class="ttdoc">Explicitly configure the decoder by passing a raw AudioSpecificConfig (ASC) or a StreamMuxConfig (SMC...</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:85</div></div>
<div class="ttc" id="aclassaac__fdk_1_1_a_a_c_decoder_f_d_k_html_ae672eb855a6c8c428f3da83c8edd0a9c"><div class="ttname"><a href="classaac__fdk_1_1_a_a_c_decoder_f_d_k.html#ae672eb855a6c8c428f3da83c8edd0a9c">aac_fdk::AACDecoderFDK::provideResult</a></div><div class="ttdeci">void provideResult(INT_PCM *data, size_t len)</div><div class="ttdoc">return the result PWM data</div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:217</div></div>
<div class="ttc" id="anamespaceaac__fdk_html"><div class="ttname"><a href="namespaceaac__fdk.html">aac_fdk</a></div><div class="ttdef"><b>Definition:</b> AACDecoderFDK.h:9</div></div>
<div class="ttc" id="anamespaceaac__fdk_html_a2778be91ce5b9583922e12ed14800ab7"><div class="ttname"><a href="namespaceaac__fdk.html#a2778be91ce5b9583922e12ed14800ab7">aac_fdk::TRANSPORT_TYPE</a></div><div class="ttdeci">TRANSPORT_TYPE</div><div class="ttdef"><b>Definition:</b> info.h:7</div></div>
<div class="ttc" id="anamespaceaac__fdk_html_a2778be91ce5b9583922e12ed14800ab7a4dcca5bcc4b82568da4a32aaf231966b"><div class="ttname"><a href="namespaceaac__fdk.html#a2778be91ce5b9583922e12ed14800ab7a4dcca5bcc4b82568da4a32aaf231966b">aac_fdk::TT_MP4_ADTS</a></div><div class="ttdeci">@ TT_MP4_ADTS</div><div class="ttdef"><b>Definition:</b> info.h:12</div></div>
<div class="ttc" id="anamespaceaac__fdk_html_a418a271f19e3b10156f92bc22288bbaea2f63d9b1bf4936c0572557d1da16bff5"><div class="ttname"><a href="namespaceaac__fdk.html#a418a271f19e3b10156f92bc22288bbaea2f63d9b1bf4936c0572557d1da16bff5">aac_fdk::AAC_PCM_MIN_OUTPUT_CHANNELS</a></div><div class="ttdeci">@ AAC_PCM_MIN_OUTPUT_CHANNELS</div><div class="ttdef"><b>Definition:</b> info.h:56</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1
</small></address>
</body>
</html>
